package com.asa.interceptor;

import com.asa.bean.User;
import com.asa.common.utils.Com;
import com.asa.common.utils.ComUtils;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 基类拦截器
 * 
 * @author Asa 创建时间: 2015年11月8日 下午5:38:47
 * @version v1.0
 */
public  class MyInterceptor implements HandlerInterceptor {
	@Override
	public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
		Com com = ComUtils.getCom();
		com.setRequest(httpServletRequest);
		com.setResponse(httpServletResponse);
		return true;
	}

	@Override
	public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {

	}

	@Override
	public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
		ComUtils.removeCom();
	}


	/**
	 * 条件不通过,进行跳转或提示处理
	 * @param response 响应对象
	 * @param redirectURL 跳转的地址
	 * @param desc 提示信息
	 * @return boolean
	 * @throws IOException 
	 */
//	 boolean handle(HttpServletResponse response, String redirectURL, String desc) throws IOException {
//		Com<Manager> com = SpringUtil.getBean("com");
//		if (com.isAjax()) { // 如果是ajax提交
//			com.write(new AjaxMessage(desc, redirectURL));
//		} else {
//			response.setStatus(302);
//			response.sendRedirect(redirectURL);
//		}
//		return false;
//	}
}
